package com.rq.rvlibrary;

import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;

import java.util.List;

public class RQDiffUtil {
    private List data;

    Handler main = new Handler(Looper.getMainLooper()) {
        @Override
        public void handleMessage(@NonNull Message msg) {
            super.handleMessage(msg);
//            RecyclerView.Adapter mAdapter = (RecyclerView.Adapter) ((Object[]) msg.obj)[0];
//            DiffUtil.DiffResult diffResult = (DiffUtil.DiffResult) ((Object[]) msg.obj)[1];
//            diffResult.dispatchUpdatesTo(mAdapter);
        }
    };

    RQDiffUtil(List data) {
        this.data = data;
    }


    public void setNewData(final List dataList, final RecyclerView.Adapter adapter) {
        new Thread(new Runnable() {
            @Override
            public void run() {
                //放在子线程中计算DiffResult
//                DiffUtil.DiffResult diffResult = DiffUtil.calculateDiff(new RQDiffCallBack(data, dataList), true);
//                Message message = main.obtainMessage();
//                message.obj = new Object[]{adapter, diffResult};//obj存放DiffResult
//                message.sendToTarget();
//                RQDiffUtil.this.data = dataList;
            }
        }).start();
    }

}
